package com.ruoyi.web.controller.lhqCreateTemporary;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.LhqCreateATemporary;
import com.ruoyi.system.service.ILhqCreateATemporaryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 创建临时课堂Controller
 * 
 * @author 林恒全
 * @date 2020-11-23
 */
@Controller
@RequestMapping("/system/temporary")
public class LhqCreateATemporaryController extends BaseController
{
    private String prefix = "system/temporary";

    @Autowired
    private ILhqCreateATemporaryService lhqCreateATemporaryService;

    @RequiresPermissions("system:temporary:view")
    @GetMapping()
    public String temporary()
    {
        return prefix + "/temporary";
    }

    /**
     * 查询创建临时课堂列表
     */
    @RequiresPermissions("system:temporary:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LhqCreateATemporary lhqCreateATemporary)
    {
        startPage();
        List<LhqCreateATemporary> list = lhqCreateATemporaryService.selectLhqCreateATemporaryList(lhqCreateATemporary);
        return getDataTable(list);
    }

    /**
     * 导出创建临时课堂列表
     */
    @RequiresPermissions("system:temporary:export")
    @Log(title = "创建临时课堂", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LhqCreateATemporary lhqCreateATemporary)
    {
        List<LhqCreateATemporary> list = lhqCreateATemporaryService.selectLhqCreateATemporaryList(lhqCreateATemporary);
        ExcelUtil<LhqCreateATemporary> util = new ExcelUtil<LhqCreateATemporary>(LhqCreateATemporary.class);
        return util.exportExcel(list, "temporary");
    }

    /**
     * 新增创建临时课堂
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存创建临时课堂
     */
    @RequiresPermissions("system:temporary:add")
    @Log(title = "创建临时课堂", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LhqCreateATemporary lhqCreateATemporary)
    {
        return toAjax(lhqCreateATemporaryService.insertLhqCreateATemporary(lhqCreateATemporary));
    }

    /**
     * 修改创建临时课堂
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LhqCreateATemporary lhqCreateATemporary = lhqCreateATemporaryService.selectLhqCreateATemporaryById(id);
        mmap.put("lhqCreateATemporary", lhqCreateATemporary);
        return prefix + "/edit";
    }

    /**
     * 修改保存创建临时课堂
     */
    @RequiresPermissions("system:temporary:edit")
    @Log(title = "创建临时课堂", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LhqCreateATemporary lhqCreateATemporary)
    {
        return toAjax(lhqCreateATemporaryService.updateLhqCreateATemporary(lhqCreateATemporary));
    }

    /**
     * 删除创建临时课堂
     */
    @RequiresPermissions("system:temporary:remove")
    @Log(title = "创建临时课堂", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lhqCreateATemporaryService.deleteLhqCreateATemporaryByIds(ids));
    }
}
